<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		Broadcastweb.eu - Paules												/
/	Site:			http://www.broadcastweb.eu												/
/	Email:			support@broadcastweb.eu													/
/	Copyright:		2011 - 2012 (c) Broadcastweb.eu											/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0003																	/
/																							/
/========================================== JooSam ========================================*/
// Joomla Security
defined('_JEXEC') or die;
jimport('joomla.application.component.view');

class JooSamViewServers extends JView{

	function display($tpl = null){

		$items = $this->get('Items');
		$pagination = $this->get('Pagination');
		$ActiveServer = JoosamHelper::currSrvActive();
		$EditServer = JoosamHelper::currSrvEdit();

		if (!function_exists('mcrypt_module_open')){
			JFactory::getApplication()->enqueueMessage(JText::_('COM_JOOSAM_VIEWS_SERVERS_003'), 'warning');
		}
		// Joomla Error Worker
		if (count($errors = $this->get('Errors'))){
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}
		$this->items = $items;
		$this->pagination = $pagination;
		$this->addToolBar();
		$this->setDocument();
		$this->srvActive = $ActiveServer;
		$this->srvOnEdit = $EditServer;
		parent::display($tpl);
	}

	protected function addToolBar(){
		$setmore = 0;
		$canDo	= JoosamHelper::getActions();
		JToolBarHelper::title(JText::_('COM_JOOSAM_VIEWS_SERVERS_001'), 'jsmServers-TitleLogo');
		if($canDo->get('core.create')){$setmore = 1; JToolBarHelper::addNew('server.add'); }
		if($canDo->get('core.edit')){$setmore = 1; JToolBarHelper::editList('server.edit'); }
		if($canDo->get('core.delete')){$setmore = 1; JToolBarHelper::deleteList('', 'servers.delete'); }
		
		if($setmore == 1){ JToolBarHelper::divider(); }
		if($canDo->get('core.edit.state')){ JToolBarHelper::custom($task = 'servers.switchto', $icon = 'move', $iconOver = '', $alt = 'Activate', $listSelect = true, $x = false);}
		if($canDo->get('core.edit')){ JToolBarHelper::custom($task = 'servers.setadmin', $icon = 'new-style', $iconOver = '', $alt = 'Set Edit', $listSelect = true, $x = false);}
		if($canDo->get('core.edit')){ JToolBarHelper::custom($task = 'servers.testconnect', $icon = 'purge', $iconOver = '', $alt = 'Test Connection', $listSelect = true, $x = false);}
		
		JToolBarHelper::divider();
		JToolBarHelper::custom($task = 'joosam.helpme', $icon = 'help', $iconOver = '', $alt = 'JHELP', $listSelect = false, $x = false);
	}

	protected function setDocument(){
		$document = JFactory::getDocument();
		$document->setTitle(JText::_('COM_JOOSAM_VIEWS_SERVERS_002'));
	}
}